var productStock = function(){
    var html = '<div style="margin: 10px">\n' +
        '<div style="margin-top: 10px;margin-right: 20px">\n' +
        '    <form class="layui-form" action="javascript:;" id="selectStockForm">\n' +
        '        <div class="layui-form-item">\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">产品名称</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <input type="text" name="productId" autocomplete="off" placeholder="请输入产品名"\n' +
        '                           class="layui-input">\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">仓库</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="stockId" lay-search=""></select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '        </div>\n' +
        '            <div class="layui-form-item">\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">起始时间</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <input type="text" name="beginDate" id="date1" lay-verify="datetime" placeholder="起始时间"\n' +
        '                               autocomplete="off" class="layui-input">\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">截至时间</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <input type="text" name="endDate" id="date2" lay-verify="datetime" placeholder="结束时间"\n' +
        '                               autocomplete="off" class="layui-input">\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <div class="layui-input-block">\n' +
        '                        <button class="layui-btn" lay-submit="" lay-filter="demo2">立即搜索</button>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '    </form>\n' +
        '</div>\n' +
        '    <hr style="margin-bottom: 20px">\n' +
        '    <div style="margin-left: 10px;margin-right: 10px">\n' +
        '        <table class="layui-hide" id="demo" lay-filter="test"></table>\n' +
        '    </div>\n' +
        '    <input id="productStock-addProductHidden" value="" hidden="hidden">\n' +
        '</div>';
    layui.use(['table', 'form', 'jquery', 'element', 'laydate'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.jquery
            , laydate = layui.laydate
            , element = layui.element;
        $("#mainbody").html(html);
        form.render();
        //日期
        laydate.render({
            elem: '#date1'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#date2'
            , type: 'datetime'
        });

        var tableRender = function () {
            //执行一个 table 实例

            table.render({
                elem: '#demo'
                , id:"layuiTable"
                , url: '/stockOut/getStockPro' //数据接口
                , title: '库存明细表'
                , page: true //开启分页
                , toolbar: 'default'
                , limit: 10
                , limits: [10, 20, 30]
                , cols: [[ //表头
                    {type: 'numbers',align: 'center', title: '序号'}
                    , {field: 'proName', align: 'center', title: '产品名称', width: 130}
                    , {field: 'stockName', align: 'center', title: '仓库名称', width: 130}
                    , {field: 'productSpec', align: 'center', title: '产品规格', width: 250}
                    , {field: 'count', align: 'center', title: '数量', width: 70}
                    , {field: 'unit', align: 'center', title: '单位', width: 70}
                    , {field: 'modifyTimeUtc', align: 'center', title: '最近入库时间', width: 200}


                ]]
            });
        }

        //初始化表格
        tableRender();

        //监听搜索按钮
        form.on('submit(demo2)', function (data) {
            var productName = data.field.productName;
            var stockId = data.field.stockId;
            var begin = data.field.beginDate;
            var end = data.field.endDate;
            table.reload('layuiTable', {
                where: {"productName": productName, "beginStr": begin, "endStr": end, "stockId": stockId}
            });
        });

    })
}